# 数据处理层Model，实现数据的写入write和读取
import json


def read_data(path):
    with open(path, mode='r', encoding='utf-8') as f:
        data = json.load(f)
    return data


def write_data(account_data_list, path):
    with open(path, mode='w', encoding='utf-8') as f:
        json.dump(account_data_list, f, ensure_ascii=False)


if __name__ == '__main__':
    # 测试一下write_data()
    path = r'account.json'
    account_data_list = [{"data_discuz": "2021/8/21 09:00:00", "item": "工资", "classification": "收入", "amount": 20000},
                         {"data_discuz": "2021/8/21 09:00:00", "item": "聚餐", "classification": "支出", "amount": -200},
                         {"data_discuz": "2021/8/21 09:00:00", "item": "洗澡", "classification": "支出", "amount": -10}]
    write_data(account_data_list, path)
